﻿@{
    const string buttonType = ButtonType.Dashed;
    // ReSharper disable once AccessToStaticMemberViaDerivedType
    const string buttonSize = ButtonSize.Small;
}
<GridRow Gutter="16">
    <GridCol>
        <Button Type="@buttonType" Size="@buttonSize"
                OnClick="OnCheckAll">
            全选
        </Button>
    </GridCol>
    <GridCol>
        <Button Type="@buttonType" Size="@buttonSize"
                OnClick="OnUncheckAll">
            取消全选
        </Button>
    </GridCol>
</GridRow>
<Divider/>
<Tabs DefaultActiveKey="@PermissionGroups.FirstOrDefault()?.Name" TabPosition="TabPosition.Left">
    @foreach (var permissionGroup in PermissionGroups)
    {
        var groupName = permissionGroup.Name;

        <TabPane Key="@groupName" Tab="@groupName">
            <GridRow @key="groupName" Gutter="16">
                <GridCol Span="10">
                    <h3>@groupName</h3>
                </GridCol>
                <GridCol Offset="3">
                    <Button Type="@buttonType" Size="@buttonSize"
                            OnClick="() => OnCheckGroupAll(groupName)">
                        全选
                    </Button>
                </GridCol>
                <GridCol>
                    <Button Type="@buttonType" Size="@buttonSize"
                            @onclick="() => OnUncheckGroupAll(groupName)">
                        取消全选
                    </Button>
                </GridCol>
            </GridRow>
            <Divider/>
            <Tree @key="@TreeComponentKey"
                  TItem="Permission"
                  @ref="_treeDir[groupName]"
                  Id="@groupName"
                  Checkable="true"
                  DataSource="permissionGroup.Permissions"
                  TitleExpression="x => x.DataItem.DisplayName"
                  KeyExpression="x => x.DataItem.Code"
                  ChildrenExpression="x => x.DataItem.Children"
                  DefaultCheckedKeys="AssignedPermissionCodes.Intersect(_treeKeysDir[groupName]).ToArray()"
                  DisabledExpression="x => DisabledPermissionCodes.Contains(x.DataItem.Code) || !x.DataItem.IsEnabled"
                  CheckStrictly="true"
                  DefaultExpandAll="true"
                  OnCheck="args => OnTreeChange(args,groupName)"/>
        </TabPane>
    }
</Tabs>